-
Notifications
You must be signed in to change notification settings - Fork 0
Standardize command module structure with handler.rs and subcommands folder #74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
josecelano
merged 5 commits into
main
from
copilot/organize-subcommands-folder-structure
Oct 29, 2025
Merged
Standardize command module structure with handler.rs and subcommands folder #74
josecelano
merged 5 commits into
main
from
copilot/organize-subcommands-folder-structure
Oct 29, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Co-authored-by: josecelano <[email protected]>
Co-authored-by: josecelano <[email protected]>
Co-authored-by: josecelano <[email protected]>
Co-authored-by: josecelano <[email protected]>
Copilot
AI
changed the title
[WIP] Organize subcommands in dedicated folder structure
Standardize command module structure with handler.rs and subcommands folder
Oct 28, 2025
Copilot finished work on behalf of
josecelano
October 28, 2025 22:01
josecelano
approved these changes
Oct 29, 2025
Member
josecelano
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 664e1c7
josecelano
added a commit
that referenced
this pull request
Oct 29, 2025
ec977df fix: update import path in merged template.rs file (copilot-swe-agent[bot]) 5786545 chore: format code after refactoring (copilot-swe-agent[bot]) 1bdb9c4 refactor: move config module from domain to create command handler (copilot-swe-agent[bot]) 6e36037 Initial plan (copilot-swe-agent[bot]) Pull request description: ## ✅ Move config module from domain to create command handler - COMPLETE Successfully moved `src/domain/config/` to `src/application/command_handlers/create/config/` to align with DDD principles. ### Changes Summary **Module relocation:** - Moved `src/domain/config/` → `src/application/command_handlers/create/config/` - Updated module declarations in `src/domain/mod.rs` and `src/application/command_handlers/create/mod.rs` **Import path updates:** - Application layer: 5 files (handler, errors, tests) - Presentation layer: 4 files (config_loader, environment subcommand, errors, template subcommand) - Testing utilities: 1 file (e2e tasks) - Documentation: 20+ doc examples **Merge resolution:** - Merged changes from main branch (PR #74) - Fixed import path in new `template.rs` file created in merged PR ### Verification ✅ - ✅ `cargo build` - compiles successfully - ✅ `cargo test --lib` - all 1002 tests pass - ✅ `cargo run --bin linter clippy` - no warnings - ✅ `cargo fmt` - formatting correct - ✅ Merge conflicts resolved successfully ### Impact This refactoring improves architecture by: - ✅ **DDD Compliance**: Removed DTOs from domain layer - ✅ **Higher Cohesion**: Config module now co-located with create command handler - ✅ **Clearer Boundaries**: Domain layer remains pure business logic - ✅ **Better Discoverability**: All create command code in one place - ✅ **No Breaking Changes**: Internal refactoring only ### Ready for Merge All verification steps complete. Merge conflicts resolved. The refactoring successfully aligns the codebase with DDD principles while maintaining all existing functionality. <!-- START COPILOT CODING AGENT SUFFIX --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>Move config module from domain to create command handler</issue_title> > <issue_description>## 📋 Overview > > Move the `src/domain/config/` module to `src/application/command_handlers/create/config/` to align with DDD principles and improve code organization. > > **Current Location (Incorrect):** > ``` > src/domain/config/ > ``` > > **Target Location (Correct):** > ``` > src/application/command_handlers/create/config/ > ``` > > ## 🎯 Problem > > The config module is currently misplaced in the domain layer, violating Domain-Driven Design principles: > > 1. **Serialization concerns in domain**: Uses `serde::Deserialize` for JSON parsing (data transfer concern, not business logic) > 2. **Infrastructure operations in domain**: Contains `generate_template_file()` with `tokio::fs` I/O operations > 3. **String-based primitives**: Uses raw `String` types instead of domain value objects (`EnvironmentName`, `Username`) > 4. **Acts as DTO**: Converts external formats to domain types via `to_environment_params()` - this is application layer responsibility > 5. **Low cohesion**: Exclusively used by create command but separated from it by layer boundaries > > ## ✅ Solution > > Move config module to be nested under the create command handler for: > > - ✅ **DDD compliance**: Removes DTOs from domain layer > - ✅ **Higher cohesion**: Config lives with its only consumer > - ✅ **Clearer boundaries**: Domain remains pure business logic > - ✅ **Better discoverability**: All create command code in one place > - ✅ **No premature abstraction**: No generic `dto/` folder for single use > > ## 📚 Documentation > > Full refactoring plan with detailed implementation checklist: > 👉 [docs/refactors/plans/move-config-to-create-command.md](https://github.com/torrust/torrust-tracker-deployer/blob/main/docs/refactors/plans/move-config-to-create-command.md) > > ## 📝 Implementation Steps > > The plan includes 9 major steps: > > 1. Create new directory structure > 2. Move all 4 files (`mod.rs`, `environment_config.rs`, `ssh_credentials_config.rs`, `errors.rs`) > 3. Update module declarations > 4. Update imports in application layer (5 files) > 5. Update imports in presentation layer (3 files) > 6. Update imports in testing utilities (1 file) > 7. Update documentation and doc examples > 8. Clean up old directory > 9. Comprehensive verification (build, test, lint, doc) > > ## 🧪 Testing > > - All existing tests must continue to pass > - No behavior changes, only import path updates > - Verification includes: `cargo build`, `cargo test`, linters, documentation > > ## 🏗️ Architecture > > This refactoring aligns with the project's DDD architecture where: > > - **Domain Layer**: Pure business logic, entities, value objects > - **Application Layer**: Use cases, command handlers, DTOs > - **Presentation Layer**: CLI, user interaction, config loading > - **Infrastructure Layer**: External tools, file system, SSH > > The config module is a DTO layer for the create command use case, hence belongs in application layer. > > ## ⏱️ Estimated Effort > > **Time**: 1-2 hours > **Complexity**: Medium (multiple file moves, import updates) > **Risk**: Low (no behavior changes, only structural) > > ## 🔗 Related > > - [Development Principles](https://github.com/torrust/torrust-tracker-deployer/blob/main/docs/development-principles.md) > - [DDD Architecture](https://github.com/torrust/torrust-tracker-deployer/blob/main/docs/codebase-architecture.md) > </issue_description> > > ## Comments on the Issue (you are @copilot in this section) > > <comments> > </comments> > </details> - Fixes #75 <!-- START COPILOT CODING AGENT TIPS --> --- 💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs. ACKs for top commit: josecelano: ACK ec977df Tree-SHA512: abb7f92e883fc049919f82383a76984ee29cc8416b18f0a0f0588e1d9e68a4e28cf9c560bb4e367ce4725c6f1c2c724e540131c41ad3314832c7a11713fd1a91
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Inconsistent naming (
command.rsvssubcommand.rs) and flat file structure made it unclear which commands had subcommands. This establishes two clear patterns.Changes
Pattern 1 - Simple commands:
destroy/command.rs→handler.rsPattern 2 - Commands with subcommands:
create/subcommands/directory structuresubcommands/environment.rs(environment creation logic)subcommands/template.rs(template generation logic)create/subcommand.rs→handler.rs(now a simple router)Documentation:
docs/contributing/module-organization.mdStructure
All 46 tests passing, no behavioral changes.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.